/**
 * 从输入内容中找出最长的一行并输出到屏幕上
 */

#include <stdio.h>

#define MAXLINE 1000

int getlines(char s[], int lim);
void copy(char to[], char from[]);

int main() {
    int len, max;
    char line[MAXLINE], longest[MAXLINE];

    max = 0;
    while((len = getlines(line, MAXLINE)) > 0) {
        if (len > max) {
            max = len;
            copy(longest, line);
        }
    }
    if (max > 0) printf("%s", longest);

    return 0;
}

// 从输出中获取内容凑成一行直到遇到换行符或者达到lim限制长度
int getlines(char s[], int lim) {
    int i, c;
    for( i = 0; i < lim-1 && (c = getchar()) != EOF && c != '\n'; i++) {
        s[i] = c;
    }
    if (c == '\n') {
        s[i] = '\n';
        i++;
    }
    s[i] = '\0';

    return i;
}

void copy(char to[], char from[]) {
    int i = 0;
    while((to[i] = from[i]) != '\0') i++;
}
